﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class UI : MonoBehaviour {

	public GameObject configCube;

	public void Init(){
		Config config = configCube.GetComponent<Config> ();
		config.Chapter = 1;
		config.Player1 = 4;
		config.Player2 = 7;
		config.Player1Num = Config.gameConfig.LifeNum;
		config.Player2Num = Config.gameConfig.LifeNum;
		config.Score1 = 0;
		config.Score2 = 0;
		config.Status = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 2; j++) {
				config.ScorePoint [i, j] = 0;
			}
		}
	}

	public void OnClickHelp() {
		GameObject obj = gameObject.GetComponent<RectTransform> ().Find ("Helper").gameObject;
		obj.SetActive ( !obj.activeSelf );
	}

	public void OnClickStartOne() {
		Init ();
		configCube.GetComponent<Config> ().Num = 1;
		configCube.GetComponent<Config> ().Player2Num = 0;
		DontDestroyOnLoad (configCube);
		SceneManager.LoadScene ("GAME");
	}

	public void OnClickStartTwo() {
		Init ();
		configCube.GetComponent<Config> ().Num = 2;
		DontDestroyOnLoad (configCube);
		SceneManager.LoadScene ("GAME");
	}

	public void OnClickLoad() {
		Config config = configCube.GetComponent<Config> ();
		if (config.Load () == true) {
			DontDestroyOnLoad (configCube);
			SceneManager.LoadScene ("GAME");
		} else {
			GameObject btn = gameObject.GetComponent<RectTransform> ().Find ("btnTip").gameObject;
			btn.GetComponent<RectTransform> ().Find ("tip").gameObject.GetComponent<Text> ().text = "提示信息：没有可读存档";
		}
	}
}
